import { modal } from 'vue-strap'
import { getBuyTypeList, updateBuyType, showMsg } from '../../../../../vuex/action.js'

export default {
  data() {
    return {
      showUpdateBuyTypeModal: false
    }
  },
  props: {
    buytype: {
      type: Object,
      default() {
        return {
          title: '', //名称
          days: '', //天数
          price: '', //原始价
          actualPrice: '', //折后价
          amountType: 1 //0-人民币 1-港币 2-美元
        }
      }
    }
  },
  methods: {
    checkValid() {
      if (this.buytype.title.length === 0) {
        return '请输入套餐名称'
      } else if (this.buytype.days.length === 0) {
        return '请输入天数'
      } else if (this.buytype.price.length === 0) {
        return '请输入原始价'
      } else if (this.buytype.actualPrice.length === 0) {
        return '请输入折后价'
      }
    },
    evtUpdateBuyType() {
      let validMsg = this.checkValid()
      if (validMsg) {
        return this.xShowMsg({
          type: 'danger',
          content: validMsg
        })
      }

      this.xUpdateBuyType(this.buytype)
        .then((res) => {
          this.showUpdateBuyTypeModal = false
          this.$dispatch('on_refresh_list')
        })
    }
  },
  components: {
    modal: modal
  },
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xUpdateBuyType: updateBuyType,
      xGetBuyTypeList: getBuyTypeList
    }
  },
  ready() {}
}
